package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.QuestionOption;
import com.ruoyi.examination.service.IQuestionOptionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 选择题选项Controller
 * 
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/questionOption")
public class QuestionOptionController extends BaseController
{
    @Autowired
    private IQuestionOptionService questionOptionService;

    /**
     * 查询选择题选项列表
     */
    @RequiresPermissions("examination:questionOption:list")
    @GetMapping("/list")
    public TableDataInfo list(QuestionOption questionOption)
    {
        startPage();
        List<QuestionOption> list = questionOptionService.selectQuestionOptionList(questionOption);
        return getDataTable(list);
    }

    /**
     * 导出选择题选项列表
     */
    @RequiresPermissions("examination:questionOption:export")
    @Log(title = "选择题选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionOption questionOption)
    {
        List<QuestionOption> list = questionOptionService.selectQuestionOptionList(questionOption);
        ExcelUtil<QuestionOption> util = new ExcelUtil<QuestionOption>(QuestionOption.class);
        util.exportExcel(response, list, "选择题选项数据");
    }

    /**
     * 获取选择题选项详细信息
     */
    @RequiresPermissions("examination:questionOption:query")
    @GetMapping(value = "/{optionId}")
    public AjaxResult getInfo(@PathVariable("optionId") String optionId)
    {
        return success(questionOptionService.selectQuestionOptionByOptionId(optionId));
    }

    /**
     * 新增选择题选项
     */
    @RequiresPermissions("examination:questionOption:add")
    @Log(title = "选择题选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionOption questionOption)
    {
        return toAjax(questionOptionService.insertQuestionOption(questionOption));
    }

    /**
     * 修改选择题选项
     */
    @RequiresPermissions("examination:questionOption:edit")
    @Log(title = "选择题选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionOption questionOption)
    {
        return toAjax(questionOptionService.updateQuestionOption(questionOption));
    }

    /**
     * 删除选择题选项
     */
    @RequiresPermissions("examination:questionOption:remove")
    @Log(title = "选择题选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{optionIds}")
    public AjaxResult remove(@PathVariable String[] optionIds)
    {
        return toAjax(questionOptionService.deleteQuestionOptionByOptionIds(optionIds));
    }
}
